#!/bin/bash

###############################################
###### IRIS-Processor #########################
###############################################

# This script processes an iris-database the following way
# Input Image 	=> Segmentation result (<filename>.png)
#		=> Iris code	       (<filename>.png)


if [ $# -ne 3 ]; then
	echo 'Call with parameters <GROUNDTRUTH> <FOLDER> <OUTPUTFILE>';
	echo '<GROUNDTRUTH> ... e.g. cr1';
	echo '<FOLDER> ... where images are, e.g. JPG_CR30';
	echo '<OUTPUTFILE> ... where are distances written to?'
	exit;
fi
 
SEG_EXT=png

DIRNAME_SEG=seg
TOOLDIR=bin


TOOL=tbMaskCmp
COMPRESSED=$2/$DIRNAME_SEG
GROUNDTRUTH=$1/$DIRNAME_SEG
OUTPUTFILE=$3

rm -rf $OUTPUTFILE

echo 'Evaluation of of ' $COMPRESSED ' with ' $TOOL ' against ground truth ' $GROUNDTRUTH




FILELIST=`ls $GROUNDTRUTH`

# echo $FILELIST


for INPUTFILE in $FILELIST
do
  extension="${INPUTFILE##*.}"
  y=${INPUTFILE%.$extension}
  FNAME=`echo ${y##*/}`

  #echo $TOOL ': Processing ' $FNAME
  
  FILENAME=$FNAME.$SEG_EXT
  #echo $GROUNDTRUTH/$DIRNAME_SEG/$FILENAME
 
  TOOLOUTPUT=`$TOOLDIR/$TOOL $GROUNDTRUTH/$FILENAME $COMPRESSED/$FILENAME`
  ratio=${TOOLOUTPUT/WrongClassificationRatio/}
  
  `echo printf "%s,%s\n" $FNAME $ratio` >> $OUTPUTFILE

done

